import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  // 1. 定义全局共享状态
  const token = ref('')
  const userId = ref('')

  // 2. 定义操作token的方法
  const setToken = (t: string)=> token.value = t
  const setUserId = (id: string) => userId.value = id

  return { token, setToken,userId, setUserId}
}, {
  unistorage: {
    key: 'cp-user',
    paths: ['token', 'userId']
  }
})